﻿using System.Data.SqlClient;
using System.Data;

namespace ExpertMIS.Manage
{

    public class QuestionHelper
    {
        //public static string GetPagingSQL(int pageNumber, int pageSize, string sort, string field, string tableName, string queryCondition)
        //{
        //    string statement = "SELECT * FROM(SELECT ROW_NUMBER() OVER ( order by {0}) AS SerialNumber,{1} FROM {2} {3})  AS TempTable  WHERE SerialNumber >={4} AND SerialNumber<={5}";
        //    int firstNumber = ((pageNumber - 1) * pageSize + 1).ToString();
        //    int lastNumber = (pageNumber * pageSize).ToString();
        //    statement = string.Format(statement, sort, field, tableName, queryCondition, firstNumber, lastNumber);

        //    return statement;
        //}

        //public static int QueryInt(string sql)
        //{
        //    SqlConnection con = new SqlConnection(constr);
        //    SqlCommand cmd = new SqlCommand(sql, con);
        //    SqlDataReader dr = new SqlDataReader();
        //    int result = 0;

        //    con.Open();
        //    dr = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow);
        //    result = dr.GetInt32(0);
        //    con.Close;
        //    return result;
        //}

        public static DataTable GetDataTable(string sql)
        {
            DataTable dt = new DataTable();
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["Constr"].ToString());
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            con.Close();

            return dt;
        }
    }
}